package org.tio.sitexxx.service.service.qj;

import com.alibaba.fastjson.JSON;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.model.main.Imagetesting;
import org.tio.sitexxx.service.vo.Const;

import java.util.Map;

public class ImagetestingService {
    public ImagetestingService(){

    }
    private static Logger log	= LoggerFactory.getLogger(ImagetestingService.class);
    public static final ImagetestingService me	= new ImagetestingService();
    final Imagetesting dao	= new Imagetesting().dao();
    /**
     * 保存数据
     * @param imagetesting
     * @return
     */
    public boolean save(Imagetesting imagetesting) {
        return imagetesting.save();
    }

    /**
     * 根据id获取形象测试
     * @param id
     * @return
     */
    public Imagetesting fingById(int id){
        Imagetesting imagetesting;
        Record record= Db.use(Const.Db.TIO_SITE_MAIN).findFirst("select * from imagetesting where memberId=?",id);
        if(record!=null){
            imagetesting=JSON.parseObject(JSON.toJSONString(record.getColumns()),Imagetesting.class);
            return imagetesting;
        }
        System.out.println("not found imageTesting");
       return null;
    }

    /**
     * 获取用户形象测试结果
     */
    public Imagetesting getImagetesting(Map<String,Object> query){
        String sqlid = "imagetesting.getImagetesting";
        String db = Const.Db.TIO_SITE_MAIN;
        Kv cond=Kv.create().set(query);
//        Member list = Member.dao.findFirst(sql, openid);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,cond);
        Record record = Db.use(db).findFirst(sqlPara);
        if(record==null){
            return null;
        }else {
            Imagetesting imagetesting= JSON.parseObject(JSON.toJSONString(record.getColumns()),Imagetesting.class);
            return imagetesting;
        }
    }
}
